﻿using MengLin.OOP.DesignPattern.FlyWeightPattern.DoWebSite.Abstract;
using MengLin.OOP.DesignPattern.FlyWeightPattern.DoWebSite.Factory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.FlyWeightPattern.DoWebSite
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 传统写法
            //{
            //    WebSite fx = new WebSite("产品展示");
            //    fx.Use();

            //    WebSite fy = new WebSite("产品展示");
            //    fy.Use();

            //    WebSite fz = new WebSite("产品展示");
            //    fz.Use();

            //    WebSite fl = new WebSite("博客");
            //    fl.Use();

            //    WebSite fm = new WebSite("博客");
            //    fm.Use();

            //    WebSite fn = new WebSite("博客");
            //    fn.Use();
            //}
            #endregion

            #region 享元模式不带状态写法
            {
                WebSiteFactory f = new WebSiteFactory();

                AbstractWebSite fx = f.GetWebSiteCategory("产品展示");
                fx.Use();

                AbstractWebSite fy = f.GetWebSiteCategory("产品展示");
                fy.Use();

                AbstractWebSite fz = f.GetWebSiteCategory("产品展示");
                fz.Use();

                AbstractWebSite fl = f.GetWebSiteCategory("博客");
                fl.Use();

                AbstractWebSite fm = f.GetWebSiteCategory("博客");
                fm.Use();

                AbstractWebSite fn = f.GetWebSiteCategory("博客");
                fn.Use();

                Console.WriteLine("网站分类总数为 {0}", f.GetWebSiteCount());
            }
            #endregion

            #region 享元模式写法
            {
                WebSiteFactory f = new WebSiteFactory();

                AbstractWebSite fx = f.GetWebSiteCategory("产品展示");
                fx.Use(new User("小菜"));

                AbstractWebSite fy = f.GetWebSiteCategory("产品展示");
                fy.Use(new User("大鸟"));

                AbstractWebSite fz = f.GetWebSiteCategory("产品展示");
                fz.Use(new User("娇娇"));

                AbstractWebSite fl = f.GetWebSiteCategory("博客");
                fl.Use(new User("老顽童"));

                AbstractWebSite fm = f.GetWebSiteCategory("博客");
                fm.Use(new User("桃谷六仙"));

                AbstractWebSite fn = f.GetWebSiteCategory("博客");
                fn.Use(new User("南海鳄神"));

                Console.WriteLine("得到网站分类总数为 {0}", f.GetWebSiteCount());
            }
            #endregion

            Console.Read();
        }
    }

    //网站
    public class WebSite
    {
        private string _name = "";
        public WebSite(string name)
        {
            _name = name;
        }

        public void Use()
        {
            Console.WriteLine("网站分类：" + _name);
        }
    }
}
